var rMouseEvent = /^(?:mouse|contextmenu)|click/,
    rKeyboardEvent = /^(?:key(?:down|press|up))$/,
    rMousewheel = /^(?:DOMMouseScroll|mousewheel)$/;

function EventFactory(original) {
    var type=original.type;
    if(rMouseEvent.test(type)){
        return new MouseEvent(original);
    }else if(rKeyboardEvent.test(type)){
        return new KeyboardEvent(original);
    }else if(rMousewheel.test(type)){
        return new WheelEvent(original);
    }else{
        return new Event(original);
    }
}
function Event(original) {
    this.originalEvent=original;
}
Event.prototype={
    normal:function(){
        console.log('normal Event!');
    }
};


/*function MouseEvent(original) {
    Event.call(this,original);
    *//*===extend start===*//*
    var F = function () {};
    F.prototype = Event.prototype;
    this.prototype = new F;
    this.prototype.constructor=MouseEvent
    this.parent=Event.prototype
}*/

function MouseEvent(original) {
    Event.call(this,original);
    /*===extend start===*/

}
//继承方式1：
/*MouseEvent.prototype=new Event;
MouseEvent.prototype.prototype=MouseEvent;*/
/**
 方式一缺点：每完成一次继承就会创建一个Parent（new Parent)
 而一般的Parent都会有很多方法，属性，占内会很多
 */

//继承方式2：
/*MouseEvent.prototype = Event.prototype;
MouseEvent.prototype.constructor = MouseEvent;*/
/**
这个方式不用new Parent，开销是变小了
 但是有个缺点，当base的方法改变的时候，parent的方法也会跟着改变
 因为他们是对象，prototype都指向同一个引用
 */



//继承方式3：
var F = function () {};
F.prototype = Event.prototype;
MouseEvent.prototype = new F;
MouseEvent.prototype.prototype=MouseEvent;
/**

 直接继承prototype”存在上述的缺点，所以可以利用一个空对象作为中介
 F是空对象，所以几乎不占内存。这时，修改MouseEvent的prototype对象，就不会影响到Event的prototype对象。
 */
//

MouseEvent.prototype.getPageX=function(){
    console.log('MouseEvent pageX!');
};
function KeyboardEvent(original) {
    Event.call(this,original);
    KeyboardEvent.prototype=new Event;
}
KeyboardEvent.prototype.constructor=MouseEvent;
KeyboardEvent.prototype.getButton=function(){
    console.log('KeyboardEvent getButton method!');
};

function WheelEvent(original) {
    Event.call(this,original);
    WheelEvent.prototype=new Event;
}
WheelEvent.prototype.constructor=MouseEvent;
WheelEvent.prototype.getWheelData=function(){
    console.log('wheelEvent wheelData method!');
};